package com.clf.manager.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.clf.manager.entity.Currm;
import com.clf.manager.entity.Student;
import com.clf.manager.entity.StudentCurrm;
import com.clf.manager.mapper.StudentMapper;
import com.clf.manager.service.CurrmService;
import com.clf.manager.service.StudentCurrmService;
import com.clf.manager.service.StudentService;
import com.clf.manager.util.ScoreDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService  {

    @Autowired
    CurrmService currmService;

    @Autowired
    StudentCurrmService studentCurrmService;

    @Override
    public List<Currm> getcurrms(Serializable id) {
        QueryWrapper<StudentCurrm> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("student_id",id);
        List<StudentCurrm> studentCurrms = studentCurrmService.list(queryWrapper);
        for (StudentCurrm studentCurrm : studentCurrms) {
            System.out.println(studentCurrm
            );
        }
        List<Integer> currmIds = new LinkedList<>();
        for (StudentCurrm currmId : studentCurrms) {
            currmIds.add(currmId.getCurrmId());
        }
        return currmService.listByIds(currmIds);
    }

    @Override
    public List<ScoreDto> getScore(Serializable id) {
        QueryWrapper<StudentCurrm> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("student_id",id);
        List<StudentCurrm> studentCurrms = studentCurrmService.list(queryWrapper);
        List<ScoreDto> scores = new LinkedList<>();
        for (StudentCurrm studentCurrm : studentCurrms) {
            Currm currm = currmService.getById(studentCurrm.getCurrmId());
            scores.add(new ScoreDto(currm.getName(),currm.getTeacherName(),studentCurrm.getScore()));
        }
        return scores;
    }

}
